package com.ellricky.baselib.ui.order

import androidx.fragment.app.Fragment
import com.andr.common.ui.activity.BaseActivity
import com.andr.common.ui.mvp.BasePresenter
import com.andr.common.util.ToastUtil
import com.ellricky.baselib.BaseConstant
import com.ellricky.baselib.BuildConfig
import com.ellricky.baselib.R
import com.ellricky.baselib.ui.ActiveDocFragment

class CustomFragmentProviderActivity : BaseActivity<Void, BasePresenter<Void>>() {

    private val fragmentId: Int by lazy {
        intent.getIntExtra("clazz", -1)
    }

    override fun getContentLayout(): Int {
        return R.layout.base_activity_custom_fragment_provider
    }

    override fun initUIView() {
        val fragment = getFragment()
        if (fragment != null) {
            supportFragmentManager.beginTransaction().replace(R.id.container, fragment)
                .commitAllowingStateLoss()
        } else {
            if (BuildConfig.DEBUG) {
                ToastUtil.show(this, "找不到fragment")
            }
        }
    }

    private fun getFragment(): Fragment? {
        when (fragmentId) {
            BaseConstant.FRAGMENT_CLASS_CONSUME -> {
                return ClassConsumeFragment.newInstance(intent.extras)
            }
            BaseConstant.FRAGMENT_CLASS_INTEGRAL -> {
                return IntegralDetailFragment.newInstance(intent.extras)
            }
            BaseConstant.FRAGMENT_CLASS_CONSUME_RECORD -> {
                return ClassConsumeRecordFragment.newInstance(intent.extras)
            }
            BaseConstant.FRAGMENT_CLASS_VISIT_LIST -> {
                return VisitListFragment.newInstance(intent.extras)
            }
            BaseConstant.FRAGMENT_ORDER_MANAGER -> {
                return OrderManagerFragment.newInstance(intent.extras)
            }
            BaseConstant.FRAGMENT_ACTIVE_DOC -> {
                return ActiveDocFragment.newInstance()
            }
            BaseConstant.FRAGMENT_COMPLAIN_RECORD -> {
                return ComplainRecordFragment.newInstance()
            }
        }
        return null
    }
}